{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<GO> this film was just brilliant casting <UNK> <UNK> story direction <UNK> really <UNK> the part they played and you could just imagine being there robert <UNK> is an amazing actor and now the same being director <UNK> father came from the same <UNK> <UNK> as myself so i loved the fact there was a real <UNK> with this film the <UNK> <UNK> throughout the film were great it was just brilliant so much that i <UNK> the film as soon as it was released for <UNK> and would recommend it to everyone to watch and the <UNK> <UNK> was amazing really <UNK> at the end it was so sad and you know what they say if you <UNK> at a film it must have been good and this definitely was also <UNK> to the two little <UNK> that played the <UNK> of <UNK> and paul they were just brilliant children are often left out of the <UNK> <UNK> i think because the stars that play them all <UNK> up are such a big <UNK> for the whole film but these children are amazing and should be <UNK> for what they have done don't you think the whole story was so <UNK> because it was true and was <UNK> life after all that was <UNK> with us all\n"
     ]
    }
   ],
   "source": [
    "from keras.datasets import imdb\n",
    "\n",
    "(X_train,y_train), (X_test,y_test) = imdb.load_data(num_words=1000, index_from=3)\n",
    "\n",
    "# Getting the word index used for encoding the sequences\n",
    "vocab_to_int = imdb.get_word_index()\n",
    "vocab_to_int = {k:(v+3) for k,v in vocab_to_int.items()}  # Starting from word index offset onward\n",
    "\n",
    "# Creating indexes for the special characters : Padding, Start Token, Unknown words\n",
    "vocab_to_int[\"<PAD>\"] = 0\n",
    "vocab_to_int[\"<GO>\"] = 1\n",
    "vocab_to_int[\"<UNK>\"] = 2\n",
    "\n",
    "int_to_vocab = {value:key for key,value in vocab_to_int.items()}\n",
    "\n",
    "print(' '.join(int_to_vocab[id] for id in X_train[0] ))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
